range: factor out a function
authorCosimo Cecchi <cosimoc@gnome.org>
Sat, 5 Mar 2016 01:59:39 +0000 (17:59 -0800)
committerCosimo Cecchi <cosimoc@gnome.org>
Sat, 5 Mar 2016 02:13:53 +0000 (18:13 -0800)
We're going to modify this in the next commit.

gtk/gtkrange.c

index 26f2fcea865ba40b15e8a559e4b0cca945ef94bf..0d6c097b2344ee18f317f483db72c953576cdbf9 100644 (file)
@@ -2607,6 +2607,26 @@ gtk_range_key_press (GtkWidget   *widget,
   return GTK_WIDGET_CLASS (gtk_range_parent_class)->key_press_event (widget, event);
 }
 
+static void
+update_initial_slider_position (GtkRange      *range,
+                                gdouble        x,
+                                gdouble        y,
+                                GtkAllocation *slider_alloc)
+{
+  GtkRangePrivate *priv = range->priv;
+
+  if (priv->orientation == GTK_ORIENTATION_VERTICAL)
+    {
+      priv->slide_initial_slider_position = slider_alloc->y;
+      priv->slide_initial_coordinate_delta = y - slider_alloc->y;
+    }
+  else
+    {
+      priv->slide_initial_slider_position = slider_alloc->x;
+      priv->slide_initial_coordinate_delta = x - slider_alloc->x;
+    }
+}
+
 static void
 gtk_range_long_press_gesture_pressed (GtkGestureLongPress *gesture,
                                       gdouble              x,
@@ -2617,21 +2637,11 @@ gtk_range_long_press_gesture_pressed (GtkGestureLongPress *gesture,
   GtkAllocation slider_alloc;
 
   gtk_range_update_mouse_location (range);
-  gtk_css_gadget_get_border_box (priv->slider_gadget, &slider_alloc);
 
   if (priv->mouse_location == MOUSE_SLIDER && !priv->zoom)
     {
-      if (priv->orientation == GTK_ORIENTATION_VERTICAL)
-        {
-          priv->slide_initial_slider_position = slider_alloc.y;
-          priv->slide_initial_coordinate_delta = y - slider_alloc.y;
-        }
-      else
-        {
-          priv->slide_initial_slider_position = slider_alloc.x;
-          priv->slide_initial_coordinate_delta = x - slider_alloc.x;
-        }
-
+      gtk_css_gadget_get_border_box (priv->slider_gadget, &slider_alloc);
+      update_initial_slider_position (range, x, y, &slider_alloc);
       update_zoom_state (range, TRUE);
     }
 }
@@ -2693,17 +2703,7 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
       if (shift_pressed)
         update_zoom_state (range, TRUE);
 
-      if (priv->orientation == GTK_ORIENTATION_VERTICAL)
-        {
-          priv->slide_initial_slider_position = slider_alloc.y;
-          priv->slide_initial_coordinate_delta = y - slider_alloc.y;
-        }
-      else
-        {
-          priv->slide_initial_slider_position = slider_alloc.x;
-          priv->slide_initial_coordinate_delta = x - slider_alloc.x;
-        }
-
+      update_initial_slider_position (range, x, y, &slider_alloc);
       range_grab_add (range, MOUSE_SLIDER);
 
       gtk_widget_queue_draw (widget);
@@ -2753,17 +2753,7 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
       new_value = slider_low_value + (slider_high_value - slider_low_value) / 2;
 
       gtk_range_compute_slider_position (range, new_value, &slider);
-
-      if (priv->orientation == GTK_ORIENTATION_VERTICAL)
-        {
-          priv->slide_initial_slider_position = slider.y;
-          priv->slide_initial_coordinate_delta = y - slider.y;
-        }
-      else
-        {
-          priv->slide_initial_slider_position = slider.x;
-          priv->slide_initial_coordinate_delta = x - slider.x;
-        }
+      update_initial_slider_position (range, x, y, &slider);
 
       range_grab_add (range, MOUSE_SLIDER);